import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-10-20
 * Time: 19:30
 */
//class Table implements Comparable<Table> {
//
//    public int num;
//    public boolean flag;
//
//    public Table(int num) {
//        this.num = num;
//        this.flag = false;
//    }
//
//
//    @Override
//    public int compareTo(Table o) {
//        if(this.num > o.num) {
//            return 1;
//        } else if (this.num == o.num) {
//            return 0;
//        } else {
//            return -1;
//        }
//    }
//}
class People implements Comparable<People> {
    public int num;
    public int spent;


    public People(int num, int spent) {
        this.num = num;
        this.spent = spent;
    }

    @Override
    public int compareTo(People o) {
        if(this.spent > o.spent) {
            return 1;
        } else if (this.spent < o.spent) {
            return -1;
        } else {
            return 0;
        }
    }
}
public class TestEE {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            int[] table = new int[n];
            for (int i = 0; i < n; i++) {
                table[i] = scanner.nextInt();
            }
            Arrays.sort(table);
            PriorityQueue<People> queue = new PriorityQueue<>();
            for (int i = 0; i < m; i++) {
                int b = scanner.nextInt();
                int c = scanner.nextInt();
                if(b <= table[n - 1]) {
                    queue.add(new People(b, c));
                }
            }
            long sum = 0;
            int count = 0;
            boolean[] flag = new boolean[n];
            while (!queue.isEmpty()) {
                People p = queue.poll();
                for (int i = 0; i < n; i++) {
                    if(table[i] >= p.num && !flag[i]) {
                        sum += p.spent;
                        count++;
                        flag[i] = true;
                        break;
                    }
                }
                if(count == n) {
                    break;
                }
            }
            System.out.println(sum);
        }
    }
    private static int searchLeft(int begin, int end, int[] num, int n) {
        for (int i = end; i >= begin; i--) {
            if(n > num[i]) {
                return i;
            }
        }
        return -1;
    }
    private static int searchReft(int begin, int end, int[] num, int n) {
        for (int i = begin; i <= end; i++) {
            if(n > num[i]) {
                return i;
            }
        }
        return -1;
    }
    public static int[][] foundMonotoneStack (int[] nums) {
        // write code here
        int[][] ans = new int[nums.length][2];
        for (int i = 0; i < nums.length; i++) {
            int l = searchLeft(0, i, nums, nums[i]);
            int r = searchReft(i, nums.length - 1, nums,nums[i]);
            ans[i][0] = l;
            ans[i][1] = r;
        }
        return ans;
    }

    public static void main1(String[] args) {
        int[] num = {1, 1, 1, 1};
        int[][] ans = foundMonotoneStack(num);
        System.out.println(Arrays.deepToString(ans));
    }
}
